/**
 *
 * Created by Pan,hongxue, 9/7/2011 4:58:16 PM
 *
 */

function  validateVideoUrl(ori_url) 
{
	var html = download_page(ori_url);
	var matches = html.match(/"?vid"? ?(,|:) ?'?(\d+)'?/);
	if (matches == null) {
		// Not Found
	  	return 'NotFoundVideo';
	}
	var dst_url = 'http://v.iask.com/v_play.php?vid=' + matches[2];
	/* expression: <url><![CDATA[http://60.28.113.148/f/1/84f84d6931d04c869eb45b16bdae430652186099.hlv]]></url> */
	var xml_str = download_page(dst_url);
	var flv_string = parse_xml(xml_str,'durl','url');
	var timelength = parse_xml(xml_str, 'timelength');
	
	//matches = html.match(/<title>(.*?)<\/title>/);
	matches = html.match(/<title>([\s\S]*?)<\/title>/);
	if(matches){
	   return 'success_title:' + encodeURIComponent(matches[1])
	          + '\n video_urls:' + encodeURIComponent(flv_string)
	          + '\n seconds:' + Math.round(parseInt(timelength)/1000);
	}
    return 'error:empty_path';
}

/* http://video.sina.com.cn/z/youtube/index.shtml */
/* http://video.sina.com.cn/v/b/61185660-1341572584.html */
function js_get_media_url(ori_url) 
{
	var html = download_page(ori_url);
	var matches = html.match(/"?vid"? ?(,|:) ?'?(\d+)'?/);
	if (matches == null) {
		// vid not found
		return '';
	}
	var dst_url = 'http://v.iask.com/v_play.php?vid=' + matches[2];
	/* expression: <url><![CDATA[http://60.28.113.148/f/1/84f84d6931d04c869eb45b16bdae430652186099.hlv]]></url> */
	var xml_str = download_page(dst_url);
	var flv_string = parse_xml(xml_str,'durl','url');
	/*	
    var re = /<url><!\[CDATA\[(.*?)\]\]><\/url>/g;
    var match, flv_string = [];
    while(match = re.exec(xml_str))
    {
        flv_string.push(match[1]);
    }
    */

	return flv_string;
}
